package com.lagou.filter;

import com.lagou.util.TransportIPUtil;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.Filter;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Result;
import org.apache.dubbo.rpc.RpcContext;
import org.apache.dubbo.rpc.RpcException;

/**
 * @author bobcheng
 * @date 2020/6/15
 */
@Activate(group = {CommonConstants.CONSUMER})
public class TransportIPFilter implements Filter {

    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        RpcContext.getContext().setAttachment("ip", TransportIPUtil.getIp());
        return invoker.invoke(invocation);
    }

}
